home *** CD-ROM | disk | FTP | other *** search
/ Aminet 12 / Aminet 12 (1996)(GTI - Schatztruhe)[!][Jun 1996].iso / Aminet / misc / unix / mkfsc.lha / mkfsc next >
Text File  |  1996-02-29  |  3KB  |  113 lines

  1. #!/bin/sh
  2. #--
  3. #-- mkfsc - make an ftp script from an aminet index file. this file is 
  4. #--         then used in the command line:
  5. #--
  6. #--         % ftp < script_file
  7. #--
  8. #--         where 'script_file' is the file created by mkfsc.  Usage of 
  9. #--         mkfsc is:
  10. #--
  11. #--         mkfsc <index> <site:dir>
  12. #--
  13. #--         where index is the section from the aminet INDEX file that 
  14. #--         contains the list of files that are desired. "site" is the 
  15. #--         address of the aminet site and "dir" is the top level dir-
  16. #--         ectory to aminet at that site.  So for example:
  17. #--
  18. #--         % mkfsc shell-list ftp.luth.se:/pub/aminet > foo
  19. #--
  20. #--         would create a script in the file 'foo' which would be a 
  21. #--         collection of commands that would go to ftp.  Note that
  22. #--         mkfsc echos all output to stdout so that it needs to be
  23. #--         redirected to a file unless you wish to redirect the output
  24. #--         right into ftp:
  25. #--
  26. #--         % ftp < mkfsc shell-list ftp.luth.se:/pub/aminet
  27. #--
  28. #--         Note that you should have an entry in your .netrc for the
  29. #--         site you wish to go to.  That entry should look like:
  30. #--
  31. #--         machine ftp.luth.se
  32. #--         login anonymous
  33. #--         password eraugust@igate1.hac.com
  34. #--
  35. #-- bugs -  well, it's slow.  it's a script.  i needed something that
  36. #--         would work.  i thought after it was done that it might be 
  37. #--         useful for someone else.  there's probably a better way to
  38. #--         do this with a bourne shell script - if you think of it
  39. #--         let me know.
  40. #--
  41. #-- help -  email to eraugust@igate1.hac.com
  42. #--
  43. #-- mkfsc is Copyright (c)1996 Eric R. Augustine, all rights reserved.
  44. #--
  45. #-- This software is free and as such carries no warranty or garantee
  46. #-- of any sort implied or otherwise expressed.  This software should
  47. #-- not be distributed for any profit whatsoever and must be distri-
  48. #-- buted complete with all documentation and without modification 
  49. #-- except with the expressed permission of the author.
  50. #--
  51. #-- $Id: mkfsc,v 1.2 1996/02/29 23:01:20 august Exp $
  52. #--
  53. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin
  54. MYNAME=`basename $0`
  55. USAGE="usage: $MYNAME <index> <site:directory>"
  56. DATE=`date "+%H%M%S%m%d%y"`
  57. TMPFILE="$MYNAME.$DATE"
  58.  
  59. #-- check usage
  60. case $# in
  61.     2)
  62.         INDEX=$1
  63.         SITE=$2
  64.         ;;
  65.     *)
  66.         echo $USAGE
  67.         exit 0
  68.         ;;
  69. esac
  70.  
  71. #-- create the temporary file that will be modified.
  72. cp $INDEX $TMPFILE
  73. echo "END_OF_INDEX" >> $TMPFILE
  74.  
  75. #-- this value to increment "pointer" through file
  76. UPCOUNT=0
  77.  
  78. #-- get site name and top level directory name from command line
  79. TOP=`echo $SITE | cut -d: -f2`
  80. SITE=`echo $SITE | cut -d: -f1`
  81.  
  82. #-- begin creating file
  83. echo "open $SITE"
  84. echo "bin"
  85. echo "prompt"
  86.  
  87. #-- loop though file and create get and cd commands
  88. #-- if previous directory is the same create no cd command.
  89. while [ 1 ] 
  90.     do
  91.         FILE=`head -$UPCOUNT $TMPFILE | tail -1 | awk '{ print $1 }'`
  92.         DIRE=`head -$UPCOUNT $TMPFILE | tail -1 | awk '{ print $2 }'`
  93.         UPCOUNT=`expr "$UPCOUNT" + 1`
  94.         if [ "$FILE" = "END_OF_INDEX" ] ; then
  95.             echo "quit"
  96.             rm -f $TMPFILE
  97.             exit 0
  98.         fi
  99.         if [ "$DIREC" != "$DIRE" ] ; then
  100.             DIREC=$DIRE
  101.             echo "cd $TOP/$DIRE"
  102.         fi
  103.         if [ "$FILE" ] ; then
  104.             echo "get $FILE"
  105.         fi
  106.     done
  107.  
  108. #-- echo command to get out of ftp, delete temporary file and exit.
  109. echo "quit"
  110. rm -f $TMPFILE
  111. exit 0
  112.  
  113.